package uteis.airplane.ui.principal;


import uteis.sys.principal.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ActivityAirplane extends Activity {
	
	private Button btnOk;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {	
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_irplane);
		btnOk = (Button) findViewById( R.id.btnOkAirPlane);
		btnOk.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				try {
					btnOkAction();
				} catch (Exception e) {
					
					e.printStackTrace();
				}
				
			}
		});
		

	}

	protected void btnOkAction() throws Exception{
		
		// read the airplane mode setting
		boolean isEnabled = Settings.System.getInt(
		      getContentResolver(), 
		      Settings.System.AIRPLANE_MODE_ON, 0) == 1;

		// toggle airplane mode
		Settings.System.putInt(
		      getContentResolver(),
		      Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

		// Post an intent to reload
		Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
		intent.putExtra("state", !isEnabled);
		sendBroadcast(intent);
		
		
	}

}
